let context = null
const initContext = (vue) => {
	context = vue;
}

// 服务工单列表页面=》微信评价地址
const WeChatExpAsync = async (UserPhone,token)=>{
	let IdentifyId = "WeChatExp";
	let objects = {
		'UserId':UserPhone,
	};
	let strObject = JSON.stringify(objects);	
	let [error, result]  = await context.commService.postEntityAsync(IdentifyId,strObject,token);
	if(!error && result.statusCode == 200){
		return result.data;
	}
	return null;
}

//获取工单列表接口 服务工单首页.html
//tabType 1:待接单,2:待处理,3:已完工,4:提交完工
const woListAsync = async (UserPhone,PageIndex,PageSize,tabType,token)=>{
	
	let IdentifyId = "PageWoList";
	let objects = {
		'UserId':UserPhone,
		'PageIndex':PageIndex,
		'PageSize':PageSize,
		'TabType':tabType,
	};
	let strObject = JSON.stringify(objects);	
	let [error, result]  = await context.commService.postEntityAsync(IdentifyId,strObject,token);
	if(!error && result.statusCode == 200){
		console.log(result);
		return result.data;
	}
	return null;
}
//缓存工单信息 Type 1:插入更新缓存信息,2:查询缓存信息,
const CacheOrderInfoAsync = async (UserPhone,Type,WoId,WoInfo,token)=>{
	let IdentifyId = "CacheFinishOrder";
	let objects = {
		'PhoneNum':UserPhone,
		'WoId':WoId,
		'WoInfo':WoInfo,
		'type':Type
	};
	let strObject = JSON.stringify(objects);	
	let [error, result]  = await context.commService.postEntityAsync(IdentifyId,strObject,token);
	if(!error && result.statusCode == 200){
		console.log(result);
		return result.data;
	}
	return null;
}

// 接单
const WOTakingAsync = async (UserPhone,WOGUID,token)=>{
	let IdentifyId = "WOTaking";
	let objects = {
		'UserId':UserPhone,
		'WOGUID':WOGUID,
	};
	let strObject = JSON.stringify(objects);	
	let [error, result]  = await context.commService.postEntityAsync(IdentifyId,strObject,token);
	if(!error && result.statusCode == 200){
		return result.data;
	}
	return null;
}

// 工单搜索
const WOListSearchAsync = async (UserPhone,Keyword,token)=>{
	let IdentifyId = "WOListSearch";
	let objects = {
		'UserId':UserPhone,
		'Keyword':Keyword,
	};
	let strObject = JSON.stringify(objects);	
	let [error, result]  = await context.commService.postEntityAsync(IdentifyId,strObject,token);
	if(!error && result.statusCode == 200){
		return result.data;
	}
	return null;
}


const workorderlistervice = {
	initContext,
	WeChatExpAsync,
	woListAsync,
	CacheOrderInfoAsync,
	WOTakingAsync,
	WOListSearchAsync
}

export default workorderlistervice